package cn.easybuy.web.pre;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.easybuy.entity.User;
import cn.easybuy.service.UserService;
import cn.easybuy.service.impl.UserServiceImpl;

public class LoginServlet extends HttpServlet{

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String loginName=request.getParameter("loginName");
		String password=request.getParameter("password");
		UserService us=new UserServiceImpl();
		PrintWriter out=response.getWriter();
		List<User> list=us.getUsersForLogin(loginName, password);
		HttpSession session=request.getSession();
		if (list.size()>0) {
			session.setAttribute("loginName", loginName);
			response.sendRedirect("Index.jsp");
		}else {
			response.sendRedirect("Login.jsp");
		}
	}

}
